package monitor

import (
	"log"
	"net/http"

	"github.com/prometheus/client_golang/prometheus"
	"github.com/prometheus/client_golang/prometheus/promhttp"
)

var taskCounter = prometheus.NewCounterVec(
	prometheus.CounterOpts{
		Namespace: "task_scheduler",
		Subsystem: "master",
		Name:      "task_counter",
		Help:      "Total number of tasks processed",
	},
	[]string{"status"},
)

func init() {
	prometheus.MustRegister(taskCounter)
}

func TrackTaskStatus(status string) {
	taskCounter.WithLabelValues(status).Inc()
}

func StartMonitor() {
	http.Handle("/metrics", promhttp.Handler())
	log.Println("Metrics server started on port 8081")
	log.Fatal(http.ListenAndServe(":8081", nil))
}
